#include <iostream>
using std::cout;
using std::endl;

class Base{
public:
    Base(){
        cout << "Base()" << endl;
    } 

    Base(long base)
    : _base(base)
    { cout << "Base(long)" << endl; }

    void print(){
        cout << "_base:"<< _base << endl;
    }

    ~Base(){ cout << "~Base()" << endl; }
protected:
    long _base = 1;
};



class Derived
: public Base
{
public:
    Derived(){ cout << "Derived()" << endl; }

    Derived(long a,long c)
    : Base(a) //调用基类的构造，写的是基类的类名
    , _derived(c)
    {
        cout << "Derived(long * 3)" << endl;
    }
    
    //拷贝构造的显式复制基类部分
    Derived(const Derived & rhs)
    : Base(rhs._base)
    , _derived(rhs._derived)
    {}

    Derived & operator=(const Derived & rhs){
        //基类部分的复制
        Base::operator=(rhs);
        _derived = rhs._derived;
        return *this;
    }

    void print() const{
        cout << "_base:" << _base << endl;
        cout << "_derived:" << _derived << endl;
    }

    ~Derived(){ cout << "~Derived()" << endl; }
private:
    long _derived = 10;
};

void test0(){
    Derived d1(70,80);
    Derived d2 = d1;
    /* d2 = d1; */
    d1.print();
    cout << endl;
    d2.print();

    cout <<endl;
    Derived d3(100,200);
    d2 = d3;
    d3.print();
    d2.print();


}

int main(void){
    test0();
    return 0;
}
